<?php

include '../include/config.php';
if ($_POST['per'] == 'personal') {
    $target_path = '../storage/'.$_COOKIE['gid'].'/folders/' . $_POST['mdir'] . '/';
    //echo $target_path;
    $_POST['path'] = $target_path;
} else {
    $target_path = $_POST['path'];
}
$rp = $_POST['rp'];
echo $rp;
$mdir = $_POST['mdir'];
$attr = $_POST['attr'];
$date = date('Y-m-d');
$bid = $_POST['bid'];
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
//echo $target_path . '<br>' . $mdir . '<br>' . $attr . '<br>' . $date.'<br>';


if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

    if ($_POST['per'] == '') {
        $fn = time() . '_' . $bid . substr($_FILES['uploadedfile']['name'], -4);
        rename($target_path, $_POST['path'] . $fn);
    } elseif ($_POST['per'] == 'personal') {
        $fn = basename($_FILES['uploadedfile']['name']);
    }
   mysql_query("insert into me_upload_files (`Sr`,`file_name`,`uid`,`mdir`,`attr`,`date`) values(NULL,'" . $fn . "','" . $_POST['uid'] . "','" . $mdir . "','" . $attr . "','" . $date . "')") or die(mysql_error()); 
    if ($_POST['per'] == 'personal') {
        //header('Location:http://'.$_SERVER['HTTP_HOST'].'/salusme/user/folder/FolderList');
        header("Location:$rp");
    } else {
        header("Location:$rp&s=y");
    }
} else {
    //echo "There was an error uploading the file, please try again!";
    if ($_POST['per'] != '') {
        
    } else {
        header("Location:$rp&s=n");
    }
}
?>
